﻿using MvcWechat.Common;
using MvcWechat.ServiceReference1;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;

namespace MvcWechat.Controllers
{
    public class TeamController : BaseController
    {

        private ActionResult CheckView(string name="")
        {
            {
                string key = CommonPage.getKey();
                //供应商的KEY 包含下划线就标识二级 一级的KEY 不能有下划线
                if (key.Contains("__"))
                    ViewBag.IsHideSupplier = "2";
                else
                    ViewBag.IsHideSupplier = "1";
            } 
            string viewName = RouteData.Values["action"].ToString(); 
            return View(viewName);

        }
        //证书链接
        public ActionResult ViewCert(System.Web.Http.Controllers.HttpActionContext context)
        {
            //   http://api.checkgems.com/static/pdfjs/web/viewer.html?file=/api/v2/certs/{0}/{1}.pdf  //old
            var baseUrl = ConfigurationManager.AppSettings["baseUrl"];
            var url = string.Format(baseUrl + "cn/cert/{0}/{1}", Request.QueryString["certType"], Request.QueryString["certNo"]);
            var client = new System.Net.Http.HttpClient();
            client.DefaultRequestHeaders.Add("User-Agent", string.Format("{0}{1}", Request.ServerVariables["HTTP_USER_AGENT"].ToString(), " Eegia/YD"));  //数据中心要求的格式
            var result = client.GetStringAsync(url).Result;
            ViewBag.Html = result.Replace("查宝吧", "证书查询").Replace("favicon.ico", "").Replace("#nav>#cert_li>a{color: #61D19A !important;font-weight: bold;}", "#nav>#cert_li>a{color: #61D19A !important;font-weight: bold;}h2.top_title b.gia {background: url()!important;}").Replace("=\"/", string.Format("=\"{0}", baseUrl)); //替换数据中心的网页数据
            return CheckView();
        }
     
        public ActionResult Index()
        {
            return CheckView();
        }
        public ActionResult CurrencySet()
        {
            return CheckView();
        }
 
        
        public ActionResult OtherOrder()
        {
            return CheckView();
        }
        public ActionResult OtherEntry()
        {
            return CheckView();
        }
        //翡翠 
        public ActionResult Emerald()
        {
            return CheckView();
        }
        //翡翠订单 
        public ActionResult EmeraldOrder()
        {
            return CheckView();
        }
        ////首页
        //public ActionResult Index()
        //{
        //    return CheckView();
        //}
        public ActionResult ParcelCart()
        {
            return CheckView();
        }
        public ActionResult RingCart()
        {
            return CheckView();
        }
        /// <summary>
        /// 翡翠购物车
        /// </summary>
        /// <returns></returns>
        public ActionResult EmeraldCart()
        {
            return CheckView();
        }
        //团队登录 10-27
        public ActionResult Login()
        {
            return CheckView();
        }
        //修改密码
        public ActionResult Pwd()
        {
            return CheckView();
        }
        //忘记密码
        public ActionResult Forgot()
        {
            return CheckView();
        }
        public ActionResult UpLoadImg()
        {
            return CheckView();
        }
        //在线库存
        public ActionResult Inventory()
        {
            return CheckView();
        }
        //购物车列表
        public ActionResult Cart()
        {
            
            return  View();
        }
        //白色裸钻 WhiteDiamond
        public ActionResult White()
        {
            var _params = ControllerContext.RequestContext.HttpContext.Request.InputStream;
            if (_params != null && _params.Length > 0)
            {
                ViewBag.Param = System.Web.HttpUtility.UrlDecode(ManagerJson.ToJson(ControllerContext.RequestContext.HttpContext.Request.InputStream).Replace("params=", ""), System.Text.Encoding.UTF8);
            }
            else
            {
                ViewBag.Param = "";
            }
            return CheckView();
        }
        //彩色裸钻 FancyDiamond
        public ActionResult Fancy()
        {
            return CheckView();
        }
        //白色统包 WhiteParcel
        public ActionResult WhiteParcel()
        {
            return CheckView();
        }
        //彩色统包 FancyParcel
        public ActionResult FancyParcel()
        {
            return CheckView();
        }
        //成品 Ring
        public ActionResult Ring()
        {
            return CheckView();
        }
        //款式 Style
        public ActionResult Style()
        {
            return CheckView();
        }
        //代客下单
        public ActionResult Ordering()
        {
            return CheckView();
        }
        //代下单-白钻
        public ActionResult Wh()
        {
            return CheckView();
        }
        //代下单-彩钻
        public ActionResult Fy()
        {
            return CheckView();
        }
        //白钻管理
        public ActionResult MgmtWhite()
        {
            return CheckView();
        }
        //彩钻管理
        public ActionResult MgmtFancy()
        {
            return CheckView();
        }
        //白统包管理
        public ActionResult MgmtWhiteParcel()
        {
            return CheckView();
        }
        public ActionResult MgmtWhiteParcelPicture()
        {
            return CheckView();
        }
        //彩统包管理
        public ActionResult MgmtFancyParcel()
        {
            return CheckView();
        }
        //成品管理
        public ActionResult MgmtRing()
        {
            return CheckView();
        }
        //翡翠管理
        public ActionResult MgmtEmerald()
        {
            return CheckView();
        }
        //框架
        public ActionResult Frame()
        {
            return CheckView();
        }
        //客户管理
        public ActionResult Customer()
        {
            return CheckView();
        }
        //供应商管理
        public ActionResult Supplier()
        {
            return CheckView();
        }
        public ActionResult FilterSupplier()
        {
            return CheckView();
        }
        //中心供应商
        public ActionResult CenterSupplier()
        {
            return CheckView();
        }
        //屏蔽供应商
        public ActionResult Filter()
        {
            return CheckView();
        }
        //白名单
        public ActionResult WhiteList()
        {
            return CheckView();
        }
        //分销
        public ActionResult Distributor()
        {
            return CheckView();
        }
        //裸钻订单管理
        public ActionResult Order()
        {
            var _params = ControllerContext.RequestContext.HttpContext.Request.InputStream;
            if (_params != null && _params.Length > 0)
            {
                ViewBag.Param = System.Web.HttpUtility.UrlDecode(ManagerJson.ToJson(ControllerContext.RequestContext.HttpContext.Request.InputStream).Replace("params=", ""), System.Text.Encoding.UTF8);
            }
            else
            {
                ViewBag.Param = "";
            }
            ViewBag.PurchaseAgents = GetPurchaseAgents();
            ViewBag.IsShow = false;
            return CheckView();
        }
 
        //统包订单
        public ActionResult ParcelOrder()
        {
            ViewBag.PurchaseAgents = GetPurchaseAgents();
            ViewBag.IsShow = false;
            return CheckView();
        }
        //成品订单
        public ActionResult RingOrder()
        {
            ViewBag.PurchaseAgents = GetPurchaseAgents();
            ViewBag.IsShow = false;
            return CheckView();
        }
        //裸钻订单结算 11-1
        public ActionResult Settle()
        {
            return CheckView();
        }
        //团队管理
        public ActionResult Team()
        {
            return CheckView();
        }
        //我的资料
        public ActionResult Info()
        {
            return CheckView();
        }
        //全局设置
        public ActionResult Global()
        {
            return CheckView();
        }
        //首页设置
        public ActionResult Home()
        {
            return CheckView();
        }
        //公告设置
        public ActionResult Notice()
        {
            return CheckView();
        }
        //上传钻石 Diamond
        public ActionResult UpDia()
        {
            return CheckView();
        }
        //上传统包 Parcel
        public ActionResult UpPar()
        {
            return CheckView();
        }
        //上传款式 Style
        public ActionResult UpSty()
        {
            return CheckView();
        }
        //上传成品 Ring
        public ActionResult UpRing()
        {
            return CheckView();
        }
        //客户充值
        public ActionResult Charge()
        {
            return CheckView();
        }
        //申请
        public ActionResult Apply()
        {
            return CheckView();
        }
        //收支 12-3
        public ActionResult Flow()
        {
            return CheckView();
        }
        //兑换 12-30
        public ActionResult Exchange()
        {
            return CheckView();
        }
        //账户 12-8
        public ActionResult Bank()
        {
            return CheckView();
        }
        //订单录入
        public ActionResult Entry()
        {
            return CheckView();
        }
        //客户消费
        public ActionResult Pay()
        {
            return CheckView();
        }
        //统计
        public ActionResult Analyze()
        {
            return CheckView();
        }
        //周报
        public ActionResult Report()
        {
            return CheckView();
        }
        //用户活跃度
        public ActionResult AU()
        {
            return CheckView();
        }
        //更新日志
        public ActionResult Update()
        {
            return CheckView();
        }
        //公告列表
        public ActionResult NoticeList()
        {
            return CheckView();
        }
        //公告详情
        public ActionResult NoticeDetail()
        {
            return CheckView();
        }
        //职能
        public ActionResult Function()
        {
            return CheckView();
        }
        //分组
        public ActionResult Group()
        {
            return CheckView();
        }

        public ActionResult StockSearchFilter()
        {
            return CheckView();
        }
        /// <summary>
        /// 产品管理 （图文介绍等）
        /// </summary>
        /// <returns></returns>
        public ActionResult ProductManagement()
        {
            return CheckView();
        }
        public ActionResult AppointmentManagement()
        {
            return CheckView();
        }
        public ActionResult BrandManagement()
        {
            return CheckView();
        }
        public ActionResult NewsManagement()
        {
            return CheckView();
        }

        public ActionResult SupplierRole()
        {
            return CheckView();
        }
        public ActionResult OrderOwner()
        {
            if (Session["RoleID"] != null && Session["RoleID"].ToString() != "1")
            {
                return Content("<a style='cursor: pointer;color: #337ab7;' onclick='location.href=history.go(-1)'>没有权限，点击返回！！！</a>");
            }
            else
                return CheckView();
        }
        public ActionResult CustomerDesign()
        { 
            return CheckView();
        }

        public ActionResult Recommend()
        {
            return CheckView();
        }
        public ActionResult LoginMode()
        {
            return CheckView();
        }
        public ActionResult OrderRate()
        {
            return CheckView();
        }

        #region 空托
        //空托 
        public ActionResult InlaySettings()
        {
            return CheckView();
        }
        //空托订单 
        public ActionResult InlaySettingsOrder()
        {
            ViewBag.PurchaseAgents = GetPurchaseAgents();
            ViewBag.IsShow = false;
            return CheckView();
        }
        /// <summary>
        /// 空托购物车
        /// </summary>
        /// <returns></returns>
        public ActionResult InlaySettingsCart()
        {
            return CheckView();
        }
        //空托管理
        public ActionResult MgmtInlaySettings()
        {
            ViewBag.PurchaseAgents = GetPurchaseAgents();
            ViewBag.IsShow = false;
            return CheckView();
        }
        //上传
        public ActionResult UpInlaySettings()
        {
            return CheckView();
        }
        #endregion


        #region 小程序用户访问，趋势相关
        /// <summary>
        /// 获取用户访问小程序日周月留存
        
        public ActionResult AnalysisDailyRetain()
        {
            return CheckView();
        }
        /// <summary>
        /// 获取用户访问小程序数据日周月趋势
       
        public ActionResult AnalysisDailyTrend()
        {
            return CheckView();
        }
        /// <summary>
        /// 获取小程序新增或活跃用户的画像分布数据。时间范围支持昨天、最近7天、最近30天。其中，新增用户数为时间范围内首次访问小程序的去重用户数，活跃用户数为时间范围内访问过小程序的去重用户数。
        /// https://developers.weixin.qq.com/miniprogram/dev/api/getAnalysisUserPortrait.html
        /// </summary>
        /// <returns></returns>
      
        public ActionResult AnalysisUserPortrait()
        {
            return CheckView();
        }
        /// <summary>
        
        public ActionResult AnalysisVisitDistribution()
        {
            return CheckView();
        }

        /// <summary>
        /// 访问页面。目前只提供按 page_visit_pv 排序的 top200。
        
        public ActionResult AnalysisVisitPage()
        {
            return CheckView();
        }
 
        #endregion
        /////////////////////////////////////////////////页面和方法分割线/////////////////////////////////////////////////////////////////////////////////////
        private static RetailClient service = new RetailClient();
         

        /// <summary>
        /// 团队登录
        /// </summary>
        /// <returns></returns>
        public JsonResult UserLogin()
        {
            string msgInfo = "{\"msgcode\":#code,\"msginfo\":#msg,\"data\":#result}"; //templateJSON
            try
            { 
                Dictionary<string, string> dictUser = JsonConvert.DeserializeObject<Dictionary<string, string>>(GetInputJson());//字典
                Session["SupplierKey"] = dictUser["TagKey"];
                dictUser.Add("ActiveIP", HttpContext.Request.UserHostAddress);
                string jsonparam = JsonConvert.SerializeObject(dictUser);//含ActiveIP
                string userLoginResult = service.UserLogin(jsonparam);
                Dictionary<string, object> param = ManagerJson.Deserialize<Dictionary<string, object>>(userLoginResult);
                //登录成功                
                if (param["msgcode"].ToString().ToLower() != "false")
                {
                    Dictionary<string, object> userParam = ManagerJson.Deserialize<Dictionary<string, object>>(param["data"].ToString());
                    //创建Session
                    ManagerSession.SetSession("UserID", userParam["UserID"]);
                    ManagerSession.SetSession("UserName", userParam["UserName"]);
                    ManagerSession.SetSession("RealName", userParam["RealName"]);//必填
                    ManagerSession.SetSession("RoleID", userParam["RoleID"]);//必填
                    ManagerSession.SetSession("UserRoles", userParam["UserRoles"]);//必填
                }
                return Json(userLoginResult);
            }
            catch (Exception ex)
            {
                return Json(msgInfo.Replace("#code", "false").Replace("#msg", ManagerJson.Serialize(ex.Message)).Replace("#result", ManagerJson.Serialize("")));
            }
        }
        /// <summary>
        /// 退出登录
        /// </summary>
        /// <returns></returns>
        public JsonResult Logout()
        {
            try
            {
                //清除Session
                ManagerSession.RemoveSession("UserID");
                ManagerSession.RemoveSession("UserName");
                ManagerSession.RemoveSession("RealName");
                return Json(true);
            }
            catch (Exception)
            {
                return Json(false);
            }
        }
        /// <summary>
        /// 所有公告
        /// </summary>
        /// <returns></returns>
        public JsonResult GetNotices()
        {
            return Json(service.GetNotices(GetInputJson()));
        }
        /// <summary>
        /// 发布中公告
        /// </summary>
        /// <returns></returns>
        public JsonResult GetNoticeList()
        {
            return Json(service.GetNoticeList(GetInputJson()));
        }
        /// <summary>
        /// 所有全局设置 11-10
        /// </summary>
        /// <returns></returns>
        public JsonResult GetGlobals()
        {
            return Json(service.GetGlobals(GetInputJson()), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 单个全局 11-10
        /// </summary>
        /// <returns></returns>
        public JsonResult EditGlobalCurrency()
        {
            return Json(service.EditGlobalCurrency(GetInputJson()));
        }
        /// <summary>
        /// 单个全局 11-10
        /// </summary>
        /// <returns></returns>
        public JsonResult GetSettingInfo()
        {
            return Json(service.GetSettingInfo(GetInputJson()));
        }
        /// <summary>
        /// 供应商管理
        /// </summary>
        /// <returns></returns>
        public JsonResult GetSuppliers()
        {
            return Json(service.GetSuppliers(GetInputJson()));
        }
        /// <summary>
        /// 所有供应商 9-6
        /// </summary>
        /// <returns></returns>
        public JsonResult GetSupplierList()
        {
            return Json(service.GetSupplierList(GetInputJson()));
        }
        /// <summary>
        /// 订单管理
        /// </summary>
        /// <returns></returns>
        public JsonResult GetOrders()
        {
            return Json(service.GetTeamOrdersList(GetInputJson()));
        }
        public JsonResult AddSupplierRole()
        {
            return Json(service.AddSupplierRole(GetInputJson()));
        }
        
        /// <summary>
        /// 结算订单 11-2  数据库字段排序
        /// </summary>
        /// <returns></returns>
        public JsonResult SettleOrders()
        {
            return Json(service.SettleOrders(GetInputJson()));
        }
        /// <summary>
        /// 团队管理
        /// </summary>
        /// <returns></returns>
        public JsonResult GetUsers()
        {
            return Json(service.GetUsers(GetInputJson()));
        }
        /// <summary>
        /// 业务列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetSales()
        {
            return Json(service.GetSales(GetInputJson()));
        }
        /// <summary>
        /// 所有业务 9-6
        /// </summary>
        /// <returns></returns>
        public JsonResult GetSaleList()
        {
            return Json(service.GetSaleList(GetInputJson()));
        }
        /// <summary>
        /// 采购列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetPurchases()
        {
            return Json(service.GetPurchases(GetInputJson()));
        }
        /// <summary>
        /// 所有采购 9-6
        /// </summary>
        /// <returns></returns>
        public JsonResult GetPurchaseList()
        {
            return Json(service.GetPurchaseList(GetInputJson()));
        }
        public JsonResult ReviseOrders()
        {
            return Json(service.ReviseOrders(GetInputJson()));
        }
        public JsonResult RemarkOrder()
        {
            return Json(service.RemarkOrder(GetInputJson()));
        }
        public JsonResult StockOrders()
        {
            return Json(service.StockOrders(GetInputJson()));
        }
        public JsonResult ReturnOrders()
        {
            return Json(service.ReturnOrders(GetInputJson()));
        }
        public JsonResult ActiveCustomer()
        {
            return Json(service.ActiveCustomer(GetInputJson()));
        }
        public JsonResult CancelOrders()
        {
            return Json(service.CancelOrders(GetInputJson()));
        }
        public JsonResult GetAllShipNo()
        {
            return Json(service.GetAllShipNo(GetInputJson()));
        }
        public JsonResult DownloadOrder()
        {
            return Json(service.DownloadOrder(GetInputJson()));
        }
        public JsonResult ExportAllOrder()
        {
            return Json(service.ExportAllOrder(GetInputJson()));
        }
        /// <summary>
        /// 所有纯采购 9-26
        /// </summary>
        /// <returns></returns>
        public JsonResult GetPurchasers()
        {
            return Json(service.GetPurchasers(GetInputJson()));
        }
        /// <summary>
        /// 报价列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetRapnetList()
        {
            return Json(service.GetRapnetList());
        }
        /// <summary>
        /// 在线库存
        /// </summary>
        /// <returns></returns>
        public JsonResult GetInventoryInfos()
        { 
            return Json(service.GetInventoryInfos(GetParentKeyInputJson(),"")); 
        }
        public JsonResult GetInventoryInfosCount()
        {
            return Json(service.GetInventoryInfosCount(GetInputJson()));
        }

        public JsonResult ArrivalOrders()
        {
            return Json(service.ArrivalOrders(GetInputJson()));
        }
        public JsonResult CancelArrivalOrders()
        {
            return Json(service.CancelArrivalOrders(GetInputJson()));
        }
        /// <summary>
        /// 在线通知
        /// </summary>
        /// <returns></returns>
        public JsonResult GetNotice()
        {
            return Json(service.GetNotice(GetInputJson()), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 备注订单(下单备注 业务备注 采购备注 物流备注)
        /// </summary>
        /// <returns></returns>
        
        /// <summary>
        /// 转移订单
        /// </summary>
        /// <returns></returns>
        public JsonResult ModifyPurchaseUserID()
        {
            return Json(service.ModifyPurchaseUserID(GetInputJson()));
        }
        /// <summary>
        /// 移交客户 9-24
        /// </summary>
        /// <returns></returns>
        public JsonResult ModifySalesUserID()
        {
            return Json(service.ModifySalesUserID(GetInputJson()));
        }
        /// <summary>
        /// 修改密码 9-21
        /// </summary>
        /// <returns></returns>
        public JsonResult TeamModifyPassword()
        {
            return Json(service.TeamModifyPassword(GetInputJson()));
        }
        
        /// <summary>
        /// 联系方式
        /// </summary>
        /// <returns></returns>
        public JsonResult ContactSupplier()
        {
            return Json(service.ContactSupplier(GetInputJson()));
        }
        
        /// <summary>
        /// 修改运费 11-11
        /// </summary>
        /// <returns></returns>
        public JsonResult ModFreight()
        {
            return Json(service.ModFreight(GetInputJson()));
        }
        
        /// <summary>
        /// 团队资料
        /// </summary>
        /// <returns></returns>
        public JsonResult GetUserInfo()
        {
            return Json(service.GetUserInfo(GetInputJson()));
        }
        /// <summary>
        /// 修改团队资料
        /// </summary>
        /// <returns></returns>
        public JsonResult EditUser()
        {
            return Json(service.EditUser(GetInputJson()));
        }
        /// <summary>
        /// 发布公告
        /// </summary>
        /// <returns></returns>
        public JsonResult AddNotice()
        {
            return Json(service.AddNotice(GetInputJson()));
        }
        /// <summary>
        /// 添加团队
        /// </summary>
        /// <returns></returns>
        public JsonResult AddUser()
        {
            return Json(service.AddUser(GetInputJson()));
        }
        /// <summary>
        /// 团队是否存在
        /// </summary>
        /// <returns></returns>
        public JsonResult UserRegIsExist()
        {
            return Json(service.UserRegIsExist(GetInputJson()));
        }
        /// <summary>
        /// 供应商简称是否存在
        /// </summary>
        /// <returns></returns>
        public JsonResult SupplierRegIsExist()
        {
            return Json(service.SupplierRegIsExist(GetInputJson()));
        }
        /// <summary>
        /// 上架 On
        /// </summary>
        /// <returns></returns>
        public JsonResult OnShelves()
        {
            return Json(service.OnShelves(GetInputJson()));
        }
        /// <summary>
        /// 下架 Off
        /// </summary>
        /// <returns></returns>
        public JsonResult OffShelves()
        {
            return Json(service.OffShelves(GetInputJson()));
        }
        /// <summary>
        /// 添加记账明细
        /// </summary>
        /// <returns></returns>
        public JsonResult AddCharge()
        {
            return Json(service.AddCharge(GetInputJson()));
        }
        /// <summary>
        /// 添加供应商
        /// </summary>
        /// <returns></returns>
        public JsonResult AddSupplier()
        {
            return Json(service.AddSupplier(GetInputJson()));
        }
        /// <summary>
        /// 编辑供应商
        /// </summary>
        /// <returns></returns>
        public JsonResult EditSupplier()
        {
            return Json(service.EditSupplier(GetInputJson()));
        }
        public JsonResult GetSupplierInfo()
        {
            return Json(service.GetSupplierInfo(GetInputJson()));
        }
        /// <summary>
        /// 修改公告
        /// </summary>
        /// <returns></returns>
        public JsonResult EditNotice()
        {
            return Json(service.EditNotice(GetInputJson()));
        }
        /// <summary>
        /// 修改全局
        /// </summary>
        /// <returns></returns>
        public JsonResult EditGlobal()
        {
            return Json(service.EditGlobal(GetInputJson()));
        }
        /// <summary>
        /// 获取配置
        /// </summary>
        /// <returns></returns>
        public JsonResult GetSysSettingInfo()
        {
            return Json(service.GetSysSettingInfo(GetInputJson()));
        }
        /// <summary>
        /// 获取全局销售汇率 11-10
        /// </summary>
        /// <returns></returns>
        public JsonResult GetRate()
        {
            return Json(service.GetRate(GetInputJson()));
        }
        /// <summary>
        /// 获取采购汇率 9-6
        /// </summary>
        /// <returns></returns>
        public JsonResult GetExchangeRate()
        {
            return Json(service.GetExchangeRate(GetInputJson()));
        }
        /// <summary>
        /// 编辑配置
        /// </summary>
        /// <returns></returns>
        public JsonResult EditSysSettingInfo()
        {
            return Json(service.EditSysSettingInfo(GetInputJson()));
        }
        /// <summary>
        /// 单个库存资料
        /// </summary>
        /// <returns></returns>
        public JsonResult GetInventoryInfo()
        {
            return Json(service.GetInventoryInfo(GetInputJson()));
        }
        /// <summary>
        /// 上架文件File到WCF服务端
        /// </summary>
        public string UploadFile(string type = "stock")
        {
            var msg = "";
            try
            {
                HttpPostedFileBase file = HttpContext.Request.Files[0];
                FileUploadMessage request = new FileUploadMessage();
                //request.FileName = file.FileName;//文件名
                var partName = file.FileName.Substring(file.FileName.LastIndexOf("."), (file.FileName.Length - file.FileName.LastIndexOf(".")));
                request.FileName = EncodeBase64(file.FileName) + partName + HttpContext.Request.Url.Query;//文件名 2017-02-07  EncodeBase64解决中文编码
                request.FileData = file.InputStream;//文件流
                request.key =CommonPage.getKey();
                IRetail channel = service.ChannelFactory.CreateChannel();
                UpFileResult result = new UpFileResult();
                // request channel(request);//提交WCF服务端
                request.GoodsType = type; 
                result = channel.UploadFile(request); 
                msg = result.Message;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            return msg;
        }
        //成品上传
        [HttpPost]
        public string UploadFileByInlays()
        {
            return UploadFile("inlays");
        }
        //彩宝上传
        [HttpPost]
        public string UploadFileByGems()
        {
            return UploadFile("gems");
        }
        //统包上传
        [HttpPost]
        public string UploadFileByParcels()
        {
            return UploadFile("parcels");
        }
        //翡翠上传
        [HttpPost]
        public string UploadFileByEmeralds()
        {
            return UploadFile("emeralds");
        }
        //素金上传
        [HttpPost]
        public string UploadFileByPrimeGolds()
        {
            return UploadFile("primegolds");
        }
        [HttpPost]
        public string UploadFileByInlaySettings()
        {
            return UploadFile("inlaysettings");
        }
        /// <summary>
        ///Base64编码
        /// </summary>
        /// <returns>返回string</returns>
        public string EncodeBase64(string s)
        {
            var strResult = "";
            if (!string.IsNullOrEmpty(s))
            {
                strResult = Convert.ToBase64String(Encoding.Default.GetBytes(s));
            }
            return strResult;
        }
        /// <summary>
        /// 上架图片Image到WCF服务端
        /// </summary>
        public JsonResult UploadImage()
        {
            ImageUploadMessage request = new ImageUploadMessage();
            request.type = "img";
            return NewMethod(request);
        }

        private JsonResult NewMethod(ImageUploadMessage request)
        {
            //string msgInfo = "{\"msgcode\":#code,\"msginfo\":#msg}";
            string msgInfo = "{\"msgcode\":#code,\"msginfo\":\"#msg\"}";
            try
            {
                var msg = "";
                HttpFileCollection uploadFiles = System.Web.HttpContext.Current.Request.Files;
                ImageMessage[] ims = new ImageMessage[uploadFiles.Count];
                for (int i = 0; i < uploadFiles.Count; i++)
                {
                    System.Web.HttpPostedFile postedFile = uploadFiles[i];
                    string fileName = i.ToString() + postedFile.FileName;//完整的路径
                    string type = fileName.Substring(fileName.LastIndexOf(".") + 1);    //类型  
                    ImageMessage im = new ImageMessage()
                    {
                        FileName = uploadFiles[i].FileName,
                        ImageData = StreamToBytes(uploadFiles[i].InputStream)// (Stream)uploadFiles[i].InputStream
                    };
                    ims[i] = im;
                }
                request.ImageDatas = ims;
                request.TypeName = HttpContext.Request.QueryString["type"];//文件名  
                //客户端
                IRetail channel = service.ChannelFactory.CreateChannel();
                UpFileResult result = new UpFileResult();
                // request channel(request);//提交WCF服务端
                result = channel.UploadImage(request);//上传图片
                msg = result.Message;
                //}
                return Json(msg);
            }
            catch (Exception ex)
            {
                return Json(msgInfo.Replace("#code", "false").Replace("#msg", ex.Message));
            }
        }
        /// <summary>
        /// 上架视频到WCF服务端
        /// </summary>
        public JsonResult UploadVideo()
        {
            ImageUploadMessage request = new ImageUploadMessage();
            request.type = "video";
            return NewMethod(request);
        }
        public byte[] StreamToBytes(Stream stream)
        {
            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);
            // 设置当前流的位置为流的开始
            stream.Seek(0, SeekOrigin.Begin);
            return bytes;
        }
        
        /// <summary>
        /// 下载上传模板
        /// </summary>
        /// <returns></returns>
        public JsonResult DownTemplate()
        {
            return Json(service.DownTemplate());
        }
        /// <summary>
        /// 下载录入模板
        /// </summary>
        /// <returns></returns>
        public JsonResult DownEntryTemplate()
        {
            return Json(service.DownEntryTemplate());
        }
          
        /// <summary>
        /// 查看取货单
        /// </summary>
        /// <returns></returns>
        public JsonResult GetDeliverys()
        {
            return Json(service.GetDeliverys(GetInputJson()));
        }
        /// <summary>
        /// 到货日期查看 9-28
        /// </summary>
        /// <returns></returns>
        public JsonResult GetArrivals()
        {
            return Json(service.GetArrivals(GetInputJson()));
        }
        /// <summary>
        /// 上架模式（0覆盖 1追加）单例模式
        /// </summary>
        /// <returns></returns>
        public JsonResult UploadFileState(string uploadParam)
        {
            return Json(service.UploadFileState(GetInputJson()));
        }
        /// <summary>
        /// 客户购物车详情列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCartInfos()
        {
            return Json(service.GetCartInfos(GetParentKeyInputJson()));
        }
        /// <summary>
        /// 购物车列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCarts()
        {
            return Json(service.GetCarts(GetInputJson()));
        }
        /// <summary>
        /// 录入订单
        /// </summary>
        /// <returns></returns>
        public JsonResult EntryOrder()
        {
            return Json(service.EntryOrder(GetInputJson()));
        }
        /// <summary>
        /// 检查录入 9-27
        /// </summary>
        /// <returns></returns>
        public JsonResult EntryCheck()
        {
            return Json(service.EntryCheck(GetInputJson()));
        }
        /// <summary>
        /// 银行账户 12-8
        /// </summary>
        /// <returns></returns>
        public JsonResult GetBanks()
        {
            return Json(service.GetBanks(GetInputJson()));
        }
        /// <summary>
        /// 银行账户 12-21
        /// </summary>
        /// <returns></returns>
        public JsonResult GetBankList()
        {
            return Json(service.GetBankList(GetInputJson()));
        }
        /// <summary>
        /// 银行账户
        /// </summary>
        /// <returns></returns>
        public JsonResult GetBank()
        {
            return Json(service.GetBank(GetInputJson()));
        }
        /// <summary>
        /// 添加账户
        /// </summary>
        /// <returns></returns>
        public JsonResult AddBank()
        {
            return Json(service.AddBank(GetInputJson()));
        }
        /// <summary>
        /// 账户对账
        /// </summary>
        /// <returns></returns>
        public JsonResult EditBank()
        {
            return Json(service.EditBank(GetInputJson()));
        }
        /// <summary>
        /// 账户收支 12-3
        /// </summary>
        /// <returns></returns>
        public JsonResult GetFlows()
        {
            return Json(service.GetFlows(GetInputJson()));
        }
        /// <summary>
        /// 添加流水
        /// </summary>
        /// <returns></returns>
        public JsonResult AddFlow()
        {
            return Json(service.AddFlow(GetInputJson()));
        }
        /// <summary>
        /// 流水统计 12-13
        /// </summary>
        /// <returns></returns>
        public JsonResult FlowNumber()
        {
            return Json(service.FlowNumber(GetInputJson()));
        }
        /// <summary>
        /// 修改流水
        /// </summary>
        /// <returns></returns>
        public JsonResult EditFlow()
        {
            return Json(service.EditFlow(GetInputJson()));
        }
        /// <summary>
        /// 导出流水
        /// </summary>
        /// <returns></returns>
        public JsonResult ExportFlows()
        {
            return Json(service.ExportFlows(GetInputJson()));
        }
        /// <summary>
        /// 审核流水
        /// </summary>
        /// <returns></returns>
        public JsonResult ModifyFlow()
        {
            return Json(service.ModifyFlow(GetInputJson()));
        }
        /// <summary>
        /// 收支详情
        /// </summary>
        /// <returns></returns>
        public JsonResult GetFlow()
        {
            return Json(service.GetFlow(GetInputJson()));
        }
        /// <summary>
        /// 订单详情OrderIDs
        /// </summary>
        /// <returns></returns>
        public JsonResult GetOrderIDsDetail()
        {
            return Json(service.GetOrderIDsDetail(GetInputJson()));
        }
        /// <summary>
        /// 客户充值列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCharges()
        {
            return Json(service.GetCharges(GetInputJson()));
        }
        /// <summary>
        /// 导出充值 12-3
        /// </summary>
        /// <returns></returns>
        public JsonResult ExportCharges()
        {
            return Json(service.ExportCharges(GetInputJson()));
        }
        /// <summary>
        /// 兑换列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetExchanges()
        {
            return Json(service.GetExchanges(GetInputJson()));
        }
        /// <summary>
        /// 最近的采购汇率
        /// </summary>
        /// <returns></returns>
        //public JsonResult GetExchangeList()
        //{
        //    
        //    
        //    return Json(service.GetExchangeList(GetRequestParam()));;
        //}
        /// <summary>
        /// 兑换/采购账户入账
        /// </summary>
        /// <returns></returns>
        public JsonResult ModifyExchange()
        {
            return Json(service.ModifyExchange(GetInputJson()));
        }
        /// <summary>
        /// 转账到
        /// </summary>
        /// <returns></returns>
        public JsonResult BankTransfer()
        {
            return Json(service.BankTransfer(GetInputJson()));
        }
        /// <summary>
        /// 直接账户充值
        /// </summary>
        /// <returns></returns>
        public JsonResult DirectCharge()
        {
            return Json(service.DirectCharge(GetInputJson()));
        }
        /// <summary>
        /// 客户消费列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetPays()
        {
            return Json(service.GetPays(GetInputJson()));
        }
        /// <summary>
        /// 获取出货单订单列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetShipOrders()
        {
            return Json(service.GetShipOrders(GetInputJson()));
        }
        /// <summary>
        /// 打印出货单 9-20
        /// </summary>
        /// <returns></returns>
        public JsonResult PrintShipOrders()
        {
            return Json(service.PrintShipOrders(GetInputJson()));
        }
        /// <summary>
        /// 获取记账明细详情
        /// </summary>
        /// <returns></returns>
        public JsonResult GetChargeInfo()
        {
            return Json(service.GetChargeInfo(GetInputJson()));
        }
        /// <summary>
        /// 公告
        /// </summary>
        /// <returns></returns>
        public JsonResult GetNoticeInfo()
        {
            return Json(service.GetNoticeInfo(GetInputJson()));
        }
        /// <summary>
        /// 浏览公告
        /// </summary>
        /// <returns></returns>
        public JsonResult ViewNoticeInfo()
        {
            return Json(service.ViewNoticeInfo(GetInputJson()));
        }
        /// <summary>
        /// 修改记账明细
        /// </summary>
        /// <returns></returns>
        public JsonResult EditCharge()
        {
            return Json(service.EditCharge(GetInputJson()));
        }
        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetOrderInfo()
        {
            return Json(service.GetOrderInfo(GetInputJson()));
        }
        /// <summary>
        /// 制作出货单
        /// </summary>
        /// <returns></returns>
        public JsonResult AddShip()
        {
            return Json(service.AddShip(GetInputJson()));
        }
        /// <summary>
        /// 订单出货
        /// </summary>
        /// <returns></returns>
        public JsonResult EditShip()
        {
            return Json(service.EditShip(GetInputJson()));
        }
        /// <summary>
        /// 确认出货
        /// </summary>
        /// <returns></returns>
        public JsonResult Shipment()
        {
            return Json(service.Shipment(GetInputJson()));
        }
        /// <summary>
        /// 出货单支付
        /// </summary>
        /// <returns></returns>
        public JsonResult EditShipNo()
        {
            return Json(service.EditShipNo(GetInputJson()));
        }
        /// <summary>
        /// 付款
        /// </summary>
        /// <returns></returns>
        public JsonResult ReceiptOrders()
        {
            return Json(service.ReceiptOrders(GetInputJson()));
        }
        /// <summary>
        /// 收款
        /// </summary>
        /// <returns></returns>
        public JsonResult PayOrders()
        {
            return Json(service.PayOrders(GetInputJson()));
        }
        /// <summary>
        /// 收款
        /// </summary>
        /// <returns></returns>
        public JsonResult PayBackOrders()
        {
            return Json(service.PayBackOrders(GetInputJson()));
        }
        /// <summary>
        /// 订单支付USD
        /// </summary>
        /// <returns></returns>
        public JsonResult PayUSDOrders()
        {
            return Json(service.PayUSDOrders(GetInputJson()));
        }
        /// <summary>
        /// 删除订单
        /// </summary>
        /// <returns></returns>
        public JsonResult DelOrders()
        {
            return Json(service.DelOrders(GetInputJson()));
        }
        /// <summary>
        /// 删除订单
        /// </summary>
        /// <returns></returns>
        public JsonResult DelOrdersByOwner()
        {
            return Json(service.DelOrdersByOwner(GetInputJson()));
        }
        /// <summary>
        /// 订单状态统计
        /// </summary>
        /// <returns></returns>
        public JsonResult OrderNumber()
        {
            return Json(service.OrderNumber(GetInputJson()));
        }
        /// <summary>
        /// 订单支付状态统计
        /// </summary>
        /// <returns></returns>
        public JsonResult OrderPaymentStatusNumber()
        {
            return Json(service.OrderPaymentStatusNumber(GetInputJson()));
        }
        /// <summary>
        /// 结算订单状态统计
        /// </summary>
        /// <returns></returns>
        public JsonResult SettleOrderNumber()
        {
            return Json(service.SettleOrderNumber(GetInputJson()));
        }
        /// <summary>
        /// 结算支付状态统计
        /// </summary>
        /// <returns></returns>
        public JsonResult SettleOrderPaymentStatusNumber()
        {
            return Json(service.SettleOrderPaymentStatusNumber(GetInputJson()));
        }
        /// <summary>
        /// 每月订单统计 9-22
        /// </summary>
        /// <returns></returns>
        public JsonResult OrderMonth()
        {
            return Json(service.OrderMonth(GetInputJson()));
        }
        #region 客户
        /// <summary>
        /// 客户统计
        /// </summary>
        /// <returns></returns>
        public JsonResult CustomerNumber()
        {
            //TODO
            return Json(service.CustomerNumber(GetInputJson()));
        }
        /// <summary>
        /// 修改客户资料
        /// </summary>
        /// <returns></returns>
        public JsonResult EditCustomer()
        {
            RetailClient service = new RetailClient();
            string editCustomerJson = GetInputJson();
            return Json(service.EditCustomer(editCustomerJson));
        }     /// <summary>
        /// 所有客户
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCustomerList()
        {
            return Json(service.GetCustomerList(GetInputJson()));
        }
        /// <summary>
        /// 客户管理
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCustomers()
        {
            return Json(service.GetCustomers(GetInputJson()));
        }
        /// <summary>
        /// 添加客户
        /// </summary>
        /// <returns></returns>
        public JsonResult AddCustomer()
        {
            return Json(service.AddCustomer(GetInputJson()));
        }
        /// <summary>
        /// 客户资料
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCustomerInfo()
        {
            string getCustomerInfoJson = GetInputJson();
            return Json(service.GetCustomerInfo(getCustomerInfoJson));
        }
        #endregion
        /// <summary>
        /// 充值统计
        /// </summary>
        /// <returns></returns>
        public JsonResult ChargeNumber()
        {
            return Json(service.ChargeNumber(GetInputJson()));
        }
        /// <summary>
        /// 购物车统计
        /// </summary>
        /// <returns></returns>
        public JsonResult CartNumber()
        {
            return Json(service.CartNumber(GetInputJson()));
        }
         
        /// <summary>
        /// 周报
        /// </summary>
        /// <returns></returns>
        public JsonResult OrderReport()
        {
            return Json(service.OrderReport(GetInputJson()));
        }
        /// <summary>
        /// 更新日志 9-29
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateLog()
        {
            return Json(service.UpdateLog());
        }
        /// <summary>
        /// 更新本地报价XML 10-9
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateRapXml()
        {
            return Json(service.UpdateRapXml());
        }
        public JsonResult DelSupplier()
        {
            return Json(service.DelSupplier(GetInputJson()));
        }
        //////////////////// 裸钻管理 ///////////////////
        /// <summary>
        /// 添加裸钻
        /// </summary>
        /// <returns></returns>
        public JsonResult AddDia()
        {
            //return Json(service.AddDia(GetSecondSNKeyInputJson()));
            return Json(service.AddDia(GetInputJson()));
        }
        /// <summary>
        /// 修改裸钻
        /// </summary>
        /// <returns></returns>
        public JsonResult ModifyDia()
        {
            return Json(service.ModifyDia(GetInputJson()));
        }
        /// <summary>
        /// 删除裸钻
        /// </summary>
        /// <returns></returns>
        public JsonResult DelDia()
        {
            return Json(service.DelDia(GetInputJson()));
        }
        /// <summary>
        /// 批量调整裸钻价格
        /// </summary>
        /// <returns></returns>
        public JsonResult BatchDia()
        {
            return Json(service.BatchDia(GetInputJson()));
        }
        /// <summary>
        /// 批量更新裸钻参数
        /// </summary>
        /// <returns></returns>
        public JsonResult BatchUpdateDia()
        {
            return Json(service.BatchUpdateDia(GetInputJson()));
        }
        /////////////////AU用户活跃度///////////////////
        /// <summary>
        /// 活跃区域
        /// </summary>
        /// <returns></returns>
        public JsonResult GetActiveArea()
        {
            return Json(service.GetActiveArea(GetInputJson()));
        }
        /// <summary>
        /// 活跃时间
        /// </summary>
        /// <returns></returns>
        public JsonResult GetActiveTime()
        {
            return Json(service.GetActiveTime(GetInputJson()));
        }
        ///////////////////以下为成品Ring方法////////////////////////////////
        //成品列表
        public JsonResult GetInlays()
        {
            return Json(service.GetInlays(GetInputJson()));
        }
        //单个成品详情
        public JsonResult GetInlay()
        {
            return Json(service.GetInlay(GetInputJson()));
        }
        //添加成品
        public JsonResult AddInlays()
        {
            return Json(service.AddInlays(GetInputJson()));
        }
        //修改成品
        public JsonResult ModInlays()
        {
            return Json(service.ModInlays(GetInputJson()));
        }
        //删除成品
        public JsonResult DeleteInlays()
        {
            return Json(service.DeleteInlays(GetInputJson()));
        }
        
        /// <summary>
        /// 订单列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetRingOrders()
        {
            return Json(service.GetTeamOrdersList(GetInputJson()));
        }
        /// <summary>
        /// 单个订单
        /// </summary>
        /// <returns></returns>
        public JsonResult GetRingOrderInfo()
        {
            return Json(service.GetRingOrderInfo(GetInputJson()));
        }
        
        ////////////////////////屏蔽数据中心供应商///////////////////////////////////
        /// <summary>
        /// 所有远程供应商列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCenterSuppliers()
        {
            return Json(service.GetCenterSuppliers(GetInputJson()));
        }
        /// <summary>
        /// 单个远程供应商
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCenterSupplier()
        {
            return Json(service.GetCenterSupplier(GetInputJson()));
        }
        //所有设置列表
        public JsonResult GetSuppliersSet()
        {
            return Json(service.GetSuppliersSet(GetInputJson()));
        }
        //单个设置黑名单
        public JsonResult SetSupplier()
        {
            return Json(service.SetSupplier(GetInputJson()));
        }
        //单个设置白名单
        public JsonResult SetSupplierWhite()
        {
            return Json(service.SetSupplierWhite(GetInputJson()));
        }
        //单个列表
        public JsonResult GetSupplierSet()
        {
            return Json(service.GetSupplierSet(GetInputJson()));
        }
        //批量设置
        public JsonResult SetSuppliers()
        {
            return Json(service.SetSuppliers(GetInputJson()));
        }
        //导出裸钻
        public JsonResult GetExportUrl()
        {
            return Json(service.GetExportUrl(GetInputJson()));
        }
        /// <summary>
        /// 设置默认白名单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Init(string c)
        {
            string[] strs = ConfigurationSettings.AppSettings["OpenMenus"].Replace("diamond", "stocks").Replace("ring", "inlays").Replace("parcel", "parcels").Replace("emerald", "emeralds").Split('|');
            var msg = "resetc,";
            var setSupplierJson = "";
            var code = "AAAAAAAAAAAAAAAAAAAA";
            if (c.ToLower() == "reset")
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < strs.Length; i++)
                {
                    if (strs[i] != "other")
                    {
                        if (i == 0)
                            sb.Append("\"" + strs[i] + "\": []");
                        else
                            sb.Append(",\"" + strs[i] + "\": []");
                    }
                }
                setSupplierJson = "{\"whitelist\": {" + sb.ToString() + "}}";
                msg += c + ":" + service.SetSuppliers(setSupplierJson);
            }
            else if (c.ToLower() == "init")
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < strs.Length; i++)
                {
                    if (strs[i] != "other")
                    {
                        if (i == 0)
                            sb.Append("\"" + strs[i] + "\": [\"" + code + "\"]");
                        else
                            sb.Append(",\"" + strs[i] + "\": [\"" + code + "\"]");
                    }
                }
                setSupplierJson = "{\"whitelist\": {" + sb.ToString() + "}}";
                msg += c + ":" + service.SetSuppliers(setSupplierJson);
            }
            else
            {
                //(strs.ToList().IndexOf(c) + 1) //index
                setSupplierJson = "{'SupplierCode':'" + code + "','SupplierType':'0','category':'" + c + "','state':'true'}";
                msg += c + ":" + service.SetSupplier(setSupplierJson);
            }
            return Json(msg, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public JsonResult SetLinkInfo()
        {
            if (Session["RoleID"] != null && Session["RoleID"].ToString() == "1")
            {
                return Json(service.UpdateLink(GetInputJson()));
            }
            else
                return Json("{\"message\":\"没有权限\",\"result\":\"False\"}");
        }
        //导出裸钻
        public ActionResult GetLinkInfo()
        {
            return new ContentResult
            {
                Content = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(service.GetLink(GetInputJson())),
                ContentType = "application/json"
            };
           // return Json(service.GetLink(), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 报价列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetRapnetByParam()
        {
            return Json(service.GetRapnetByParam(GetInputJson()));
        }
        //////////////////////////////////////成品订单相关操作/////////////////////////
        
        //彩宝
        public ActionResult Gems()
        {
            return CheckView();
        }
        public ActionResult GemsOrder()
        {
            return CheckView();
        }
        public ActionResult GemsCart()
        {
            return CheckView();
        }
        public ActionResult MgmtGems()
        {
            return CheckView();
        }
        #region Gem 彩宝start
        
        ///////////////////////////////////////彩宝订单 相关/////////////////////////////////////////////////
       
        //彩宝end
        #endregion Gem 彩宝end
        /// <summary>
        /// 通过出货单查找订单
        /// </summary>
        /// <returns></returns>
        public JsonResult GetAllOrderByShipNo()
        {
            return Json(service.GetAllOrderByShipNo(GetInputJson()));
        }
         
        /// <summary>
        ///  删除出货单里面的订单
        /// </summary>
        /// <returns></returns>
        public JsonResult DeleteOrderInShipNoByOrderIdsOrShipNo()
        {
            return Json(service.DeleteOrderInShipNoByOrderIdsOrShipNo(GetInputJson()));
        }
        public ActionResult ShipOrder()
        {
            return CheckView();
        }
        /// <summary>
        /// 查询出货单
        /// </summary>
        /// <param name="CancelGemOrdersParam"></param>
        /// <returns></returns>
        public JsonResult GetJobTitleInfo()
        {
            return Json(service.GetJobTitleInfo(GetInputJson()), JsonRequestBehavior.AllowGet);
        }
        public ActionResult Role()
        {
            return CheckView();
        }
        /// <summary>
        ///  删除出货单里面的订单
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateJobTitle()
        {
            return Json(service.UpdateJobTitle(GetInputJson()));
        }
        /// <summary>
        ///  删除出货单里面的订单
        /// </summary>
        /// <returns></returns>
        public JsonResult AddJobTitle()
        {
            return Json(service.AddJobTitle(GetInputJson()));
        }
        /// <summary>
        ///  删除出货单里面的订单
        /// </summary>
        /// <returns></returns>
        public JsonResult GetMenuList()
        {
            return Json(service.GetMenuList(GetInputJson()));
        }
        /// <summary>
        /// 获取系统默认配置
        /// </summary>
        /// <returns></returns>
        public JsonResult GetThemesColor()
        {
            var inputDict = GetInputDict();
            const string tagkey = "TagKey";
            if (inputDict.ContainsKey(tagkey))
            {
                var key = GetInputDict()[tagkey].ToString();
                ConfigSettings configSetting = ConfigurationManager.GetSection(key) as ConfigSettings;
                var color = configSetting.ThemesColor;
                if (color != null && color != "")
                    return Json(color, JsonRequestBehavior.AllowGet);
                else
                    return Json("#68a32b", JsonRequestBehavior.AllowGet);
            }
            else
            {
                //log

                return Json("#68a32b", JsonRequestBehavior.AllowGet);
            }
        }
        /// <summary>
        ///  删除出货单里面的订单
        /// </summary>
        /// <returns></returns>
        public JsonResult QuerySupplierRole()
        {
            return Json(service.QuerySupplierRole(GetInputJson())); 
        }
        public JsonResult PurchaseOrder()
        {
            return Json(service.PurchaseOrder(GetInputJson()));
        }
        public string GetPurchaseAgents()
        {
            return service.GetPurchaseAgents(GetInputJson());
        }
        #region 统包Parcel 方法
         
        //
        /// <summary>
        ///// 统包订单
        ///// </summary>
        ///// <param name="catsParam"></param>
        ///// <returns></returns>
        public JsonResult GetParcelOrders() { return Json(service.GetTeamOrdersList(GetInputJson())); }
        
        #endregion
        #region otherOrder
        /// <summary>
        /// 上传图片Image到WCF服务端不用上传到数据中心，所以直接保存在客户端
        /// </summary>
        public JsonResult UploadOtherOrderImage()
        {
            Dictionary<string, ArrayList> dict = new Dictionary<string, ArrayList>();
            ArrayList arrayError = new ArrayList();
            ArrayList arraySuccess = new ArrayList();
            try
            {
                HttpFileCollection uploadFiles = System.Web.HttpContext.Current.Request.Files;
                for (int i = 0; i < uploadFiles.Count; i++)
                {
                    System.Web.HttpPostedFile postedFile = uploadFiles[i];
                    string fileName = uploadFiles[i].FileName;
                    int fileSize = uploadFiles[i].ContentLength;
                    string fileExt = Path.GetExtension(fileName).ToLower();
                    if (!(fileExt == ".png" || fileExt == ".gif" || fileExt == ".jpg" || fileExt == ".jpeg"))
                    {
                        arrayError.Add(fileName + "图片类型只能为gif,png,jpg,jpeg");
                    }
                    else
                    {
                        if (fileSize > (int)(5000 * 1024))
                        {
                            arrayError.Add(fileName + "图片大小不能超过500KB");
                        }
                        else
                        {
                            string uploadFileName = DateTime.Now.ToString("MMddhhmmss") + DateTime.Now.Ticks + fileExt;
                            try
                            {
                                string directoryPath = Server.MapPath("~/UploadImages/");
                                if (!Directory.Exists(directoryPath))//不存在这个文件夹就创建这个文件夹 
                                {
                                    Directory.CreateDirectory(Server.MapPath("~/UploadImages/"));
                                }
                                postedFile.SaveAs(Server.MapPath("~/UploadImages/") + uploadFileName);
                                arraySuccess.Add(uploadFileName);
                            }
                            catch (Exception ex)
                            {
                                arrayError.Add(fileName + ex.ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                arrayError.Add(ex.Message);
            }
            dict["error"] = arrayError;
            dict["success"] = arraySuccess;
            return Json(dict);
        }
        
        [HttpPost]
        public JsonResult GetUnit()
        {
            return Json(service.GetUnit(GetInputJson()));
        }
        [HttpPost]
        public JsonResult AddUnitName()
        {
            return Json(service.AddUnitName(GetInputJson()));
        }
        
        #endregion otherOrder
        #region Emerald 翡翠start
         
        ///////////////////////////////////////翡翠订单 相关/////////////////////////////////////////////////
        
        //彩宝end
        #endregion Gem 彩宝end
 

        #region 团队端
        /// <summary>
        /// 删除用户选中的购物车商品
        /// </summary>
        /// <returns></returns>
        public JsonResult DeleteAllCart()
        {
            return Json(service.DeleteCart(GetInputJson()));
        }
        /// <summary>
        /// 购物车中选中商品提交订单
        /// </summary>
        /// <returns></returns>
        public JsonResult SubmitOrder()
        { 
            return Json(service.SubmitOrders(GetParentKeyInputJson(),"")); 
        }
        /// <summary>
        /// 购物车中选中商品提交订单
        /// </summary>
        /// <returns></returns>
        public JsonResult DeliveryOrders()
        {
            return Json(service.DeliveryOrders(GetInputJson()));
        }
        /// <summary>
        /// 更新订单状态
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateProductsOrder()
        {
            return Json(service.UpdateProductsOrder(GetInputJson()));
        }
        /// <summary>
        /// 查询团队订单
        /// </summary>
        /// <returns></returns>
        public JsonResult GetTeamOrdersList()
        {
            return Json(service.GetTeamOrdersList(GetInputJson()));
        }
        /// <summary>
        /// 打印出货单
        /// </summary>
        /// <returns></returns>
        public JsonResult GetPrintShipOrders()
        {
            return Json(service.GetPrintShipOrders(GetInputJson()));
        }
        /// <summary>
        /// 团队 买价
        /// </summary>
        /// <returns></returns>
        public JsonResult updatePriceUSD()
        {
            return Json(service.updatePriceUSD(GetInputJson()));
        }
        /// <summary>
        /// 团队 采汇
        /// </summary>
        /// <returns></returns>
        public JsonResult updatePurchaseExchangerate()
        {
            return Json(service.updatePurchaseExchangerate(GetInputJson()));
        }
        /// <summary>
        /// 团队 采汇
        /// </summary>
        /// <returns></returns>
        public JsonResult PayAndRechargeOrders()
        {
            return Json(service.PayAndRechargeOrders(GetInputJson()));
        }
        /// <summary>
        /// 团队 采汇
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdatePlace()
        {
            return Json(service.UpdatePlace(GetInputJson()));
        }
        /// <summary>
        /// 团队 回库
        /// </summary>
        /// <returns></returns>
        public JsonResult ReStock()
        {
            return Json(service.ReStock(GetInputJson()));
        }
        /// <summary>
        /// 查询客户购物车中商品的数量
        /// </summary>
        /// <returns></returns>
        public JsonResult getCartNumByCustomerID()
        {
            return Json(service.getCartNumByCustomerID(GetInputJson()));
        }
        /// <summary>
        /// 批量修改裸钻到货时间
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateArrivalTime()
        {
            return Json(service.UpdateArrivalTime(GetInputJson()));
        }
        /// <summary>
        /// 现货修改付款状态
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateReciptStatus()
        {
            return Json(service.UpdateReciptStatus(GetInputJson()));
        }
        /// <summary>
        /// 现货修改买价
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateStockingPrice()
        {
            return Json(service.UpdateStockingPrice(GetInputJson()));
        }
        /// <summary>
        /// 现货修改汇率
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdatesStockingPurchaseExchange()
        {
            return Json(service.UpdatesStockingPurchaseExchange(GetInputJson()));
        }
        /// <summary>
        /// 现货上架
        /// </summary>
        /// <returns></returns>
        public JsonResult OnStocksBatch()
        {
            return Json(service.OnStocksBatch(GetInputJson()));
        }
        /// <summary>
        /// 现货下架
        /// </summary>
        /// <returns></returns>
        public JsonResult OffStocksBatch()
        {
            return Json(service.OffStocksBatch(GetInputJson()));
        }
        #endregion


        #region 此处存放首页特定栏目相关的函数


        //本店产品
        public JsonResult GetProducts()
        {
            return Json(service.GetProducts(GetInputJson()), JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult EditProduct()
        {
            return Json(service.EditProduct(GetInputJson()));
        }


        //品牌介绍
        public JsonResult GetBrand()
        {
            return Json(service.GetBrand(GetInputJson()),JsonRequestBehavior.AllowGet);
        }
        //首页关于我们
        public JsonResult GetBrand2()
        {
            var temp = "\"Content\":";
            var len = temp.Length;
            var text=service.GetBrand(GetInputJson());
            text = Regex.Replace(text, "<[^>]*>", "").Replace("\n", "").Replace("\r", "");
            if (text.Length >= (200 + text.IndexOf(temp) +len))
            {
                text = text.Substring(0, text.IndexOf(temp) + len) + text.Substring(text.IndexOf(temp) + len, 200 + text.IndexOf(temp) - len) + "\"}}";
            }
            return Json(text, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public JsonResult EditBrand()
        {
            return Json(service.EditBrand(GetInputJson()));
        }
        //预约进店
        public JsonResult GetAppointment()
        {
            return Json(service.GetAppointment(GetInputJson()), JsonRequestBehavior.AllowGet);
        }

        //新闻，  //帮助中心support center
        [HttpPost]
        public JsonResult GetNews()
        {
            return Json(service.GetNews(GetInputJson()));
        }

        [HttpPost] 
        public JsonResult EditNews()
        {
            return Json(service.EditNews(GetInputJson()));
        }
        [HttpPost]
        public JsonResult AddNews()
        {
            return Json(service.AddNews(GetInputJson()));
        }
        [HttpPost]
        public JsonResult DelNews()
        {
            return Json(service.DelNews(GetInputJson()));
        }

        #endregion 此处存放首页特定栏目相关的函数
        

        #region 现货增删改查
        /// <summary>
        /// 新增商品
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult AddProductData()
        {
            return Json(service.AddProductData(GetInputJson()));
        }
        /// <summary>
        /// 删除商品
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult DelProductData()
        {
            var result = service.DelProductData(GetInputJson());
            return Json(result);
        }
        /// <summary>
        /// 现货修改
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult ModifyProductData()
        {
            return Json(service.ModifyProductData(GetInputJson()));
        }
        /// <summary>
        /// 查货
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult GetProductData()
        { 
            return Json(service.GetProductData(GetParentKeyInputJson(),""));
        }
        /// <summary>
        /// 查货数量
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult GetProductDataCount()
        {
            return Json(service.GetProductDataCount(GetInputJson())); 
        }
        /// <summary>
        /// 查询单个明细
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult GetProductDataById()
        {
            return Json(service.GetProductDataById(GetInputJson()));
        }
        /// <summary>
        /// 修改金价
        /// </summary>
        /// <param name="strParam"></param>
        /// <param name="type"></param>
        /// <returns></returns> 
        public JsonResult PutPrimeGoldsPrice(string strParam)
        {
            return Json(service.PutPrimeGoldsPrice(GetInputJson()));
        }
        /// <summary>
        /// 获取金价
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult GetPrimeGoldsPrice(string strParam)
        {
            return Json(service.GetPrimeGoldsPrice(GetInputJson()));
        }
        #endregion

        #region 现货批量修改
        /// <summary>
        /// 批量修改商品
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult ModifyProducts()
        {
            return Json(service.ModifyProducts(GetInputJson()));
        }
        /// <summary>
        /// 批量修改商品
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult DelteProducts()
        {
            return Json(service.DelteProducts(GetInputJson()));
        }
        /// <summary>
        /// 更新付款状态
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns> 
        public JsonResult UpdateProductPayStatus()
        {
            return Json(service.UpdateProductPayStatus(GetInputJson()));
        }
        /// <summary>
        /// 批量改价
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult UpdateProductPrice()
        {
            return Json(service.UpdateProductPrice(GetInputJson()));
        }
        #endregion

        #region 批量上传图片视频
        /// <summary>
        /// 上架图片Image到WCF服务端
        /// </summary>
        public JsonResult UploadImages()
        {
            ImageUploadMessage request = new ImageUploadMessage();
            request.type = "img";
            return UploadImagesAndVideos(request);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private JsonResult UploadImagesAndVideos(ImageUploadMessage request)
        {
            //string msgInfo = "{\"msgcode\":#code,\"msginfo\":#msg}";
            string msgInfo = "{\"msgcode\":#code,\"msginfo\":\"#msg\"}";
            try
            {
                var msg = "";
                HttpFileCollection uploadFiles = System.Web.HttpContext.Current.Request.Files;
                ImageMessage[] ims = new ImageMessage[uploadFiles.Count];
                for (int i = 0; i < uploadFiles.Count; i++)
                {
                    System.Web.HttpPostedFile postedFile = uploadFiles[i];
                    string fileName = i.ToString() + postedFile.FileName;//完整的路径
                    string type = fileName.Substring(fileName.LastIndexOf(".") + 1);    //类型  
                    ImageMessage im = new ImageMessage()
                    {
                        FileName = uploadFiles[i].FileName,
                        ImageData = StreamToBytes(uploadFiles[i].InputStream)// (Stream)uploadFiles[i].InputStream
                    };
                    ims[i] = im;
                }
                request.ImageDatas = ims;
                request.TypeName = HttpContext.Request.QueryString["type"];//文件名  
                //客户端
                IRetail channel = service.ChannelFactory.CreateChannel();
                UpFileResult result = new UpFileResult();
                // request channel(request);//提交WCF服务端
                result = channel.UploadImagesAndVideos(request);//上传图片
                msg = result.Message;
                //}
                return Json(msg);
            }
            catch (Exception ex)
            {
                return Json(msgInfo.Replace("#code", "false").Replace("#msg", ex.Message));
            }
        }
        /// <summary>
        /// 上架视频到WCF服务端
        /// </summary>
        public JsonResult UploadVideos()
        {
            ImageUploadMessage request = new ImageUploadMessage();
            request.type = "video";
            return UploadImagesAndVideos(request);
        }
        #endregion

        #region 客户定义DIY 
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public JsonResult AddCustomerMenu()
        {
            return Json(service.AddCustomerMenu(GetInputJson()));
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public JsonResult DelCustomerMenu()
        {
            return Json(service.DelCustomerMenu(GetInputJson()));
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public JsonResult UpdateCustomerMenu()
        {
            return Json(service.UpdateCustomerMenu(GetInputJson()));
        }
        /// <summary>
        /// 查
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns>
        public JsonResult GetCustomerMenu()
        {
            return JsonK.Json(service.GetCustomerMenu(GetInputJson()), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public JsonResult AddCustomerDesign()
        {
            return Json(service.AddCustomerDesign(GetInputJson()));
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public JsonResult DelCustomerDesign()
        {
            return Json(service.DelCustomerDesign(GetInputJson()));
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public JsonResult UpdateCustomerDesign()
        {
            return Json(service.UpdateCustomerDesign(GetInputJson()));
        }
        /// <summary>
        /// 查
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns>
        public JsonResult GetCustomerDesign()
        {
            return JsonK.Json(service.GetCustomerDesign(GetInputJson()), JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 查询所有商品库存
        /// <summary>
        /// 查询所有商品库存 TAG
        /// </summary>
        /// <param name="strParam"></param>
        /// <returns></returns> 
        public JsonResult GetAllProducts()
        {
            return JsonK.Json(service.GetAllProducts(GetInputJson()), JsonRequestBehavior.AllowGet);
        }
        #endregion
        #region 测试
 
         
        #endregion

        #region 设置客户登录方式和代下单的倍率  设置推荐
        public JsonResult AddLoginMode()
        {
            return Json(service.AddLoginMode(GetInputJson(true)));
        }

        public JsonResult GetLoginMode()
        {
            return Json(service.GetLoginMode(GetInputJson()));
        }
        public JsonResult ModifyLoginMode()
        {
            return Json(service.ModifyLoginMode(GetInputJson(true)));
        }

        public JsonResult AddOrderRate()
        {
            return Json(service.AddOrderRate(GetInputJson(true)));
        }
        public JsonResult GetOrderRate()
        {
            return Json(service.GetOrderRate(GetInputJson()));
        }
        public JsonResult ModifyOrderRate()
        {
            return Json(service.ModifyOrderRate(GetInputJson(true)));
        }

        public JsonResult AddRecommend()
        {
            return Json(service.AddRecommend(GetInputJson(true)));
        }
        public JsonResult DelRecommend()
        {
            return Json(service.DelRecommend(GetInputJson(true)));
        }
        public JsonResult GetRecommend()
        {
            return Json(service.GetRecommend(GetInputJson()));
        }
        public JsonResult ModifyRecommend()
        {
            return Json(service.ModifyRecommend(GetInputJson(true)));
        }
        #endregion
        /// <summary>
        /// 财务，复核
        /// </summary>
        /// <returns></returns>
        public string ReVerify()
        {
            return service.ReVerify(GetInputJson(true));
        }
    }
}